﻿using Bankomat.States.AbstractStates;
using Bankomat.States;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Bankomat.UserInterface
{
    public class Controller
    {
        private Button myLeftButton1;
        private Button myLeftButton2;
        private Button myLeftButton3;
        private Button myLeftButton4;
        private Button myRightButton1;
        private Button myRightButton2;
        private Button myRightButton3;
        private Button myRightButton4;
        private Button myCardReader;
        private Button myCancelButton;

        public Controller(Display monitor, Button LeftButton1, Button LeftButton2, Button LeftButton3, Button LeftButton4, Button RightButton1,
            Button RightButton2, Button RightButton3, Button RightButton4, Button CardReader, Button CancelButton)
        {
            State = new InitialState();
            Monitor = monitor;
            this.myLeftButton1 = LeftButton1;
            this.myLeftButton2 = LeftButton2;
            this.myLeftButton3 = LeftButton3;
            this.myLeftButton4 = LeftButton4;
            this.myRightButton1 = RightButton1;
            this.myRightButton2 = RightButton2;
            this.myRightButton3 = RightButton3;
            this.myRightButton4 = RightButton4;
            this.myCardReader = CardReader;
            this.myCancelButton = CancelButton;

            myLeftButton1.Click += (sender, args) => { SetState(State.OptionLeft1Selected()); };
            myLeftButton2.Click += (sender, args) => { SetState(State.OptionLeft2Selected()); };
            myLeftButton3.Click += (sender, args) => { SetState(State.OptionLeft3Selected()); };
            myLeftButton4.Click += (sender, args) => { SetState(State.OptionLeft4Selected()); };

            myRightButton1.Click += (sender, args) => { SetState(State.OptionRight1Selected()); };
            myRightButton2.Click += (sender, args) => { SetState(State.OptionRight2Selected()); };
            myRightButton3.Click += (sender, args) => { SetState(State.OptionRight3Selected()); };
            myRightButton4.Click += (sender, args) => { SetState(State.CancelSelected()); };

            myCardReader.Click += (sender, args) => { SetState(State.CardReaderSelected()); };
           
        }

        public State State { get; set; }

        public Display Monitor { get; set; }

        private void SetState(State state)
        {
            if (state != null)
            {
                State = state;
                State.DisplayState(Monitor);
            }
            
        }
    }
}
